﻿using System;
using ProjectDanmaku.Scenario;
using UnityEngine;

namespace ProjectDanmaku.Core
{
    public abstract class ShootableObject : MonoBehaviour
    {
        private bool _inShootableObjects = false;
        protected int layer = 0;
        
        protected void OnEnable()
        {
            _inShootableObjects = true;
            DanmakuScenario.ShootableObjects.Add(this);

            layer = GetLayer();
        }

        private void OnDisable()
        {
            if (_inShootableObjects)
                DanmakuScenario.ShootableObjects.Remove(this);
            _inShootableObjects = false;
        }

        protected void RemoveSelfFromShootableObjects()
        {
            OnDisable();
        }

        public abstract void OnShot();
        public abstract CircleCollider GetCollider();

        protected abstract int GetLayer();

        protected CircleCollider ColliderFromPosition(float radius)
        {
            var pos = transform.position;

            return new CircleCollider(
                new Vector3(pos.x, pos.y, radius),
                layer);
        }
    }
}